using System;
using System.Timers;

namespace ebcbauteile
{
    public class PeriodicDispenser<T>
    {
        private T t;
        private readonly int timerIntervalInSeconds;

        public PeriodicDispenser()
            : this(60) {
        }

        internal PeriodicDispenser(int timerIntervalInSeconds) {
            this.timerIntervalInSeconds = timerIntervalInSeconds;
            Timer_konfigurieren();
        }

        public void In_Event(T t) {
            this.t = t;
            Out_Event(t);
        }

        public event Action<T> Out_Event;

        private void Timer_konfigurieren() {
            var timer = new Timer {
                Interval = timerIntervalInSeconds * 1000
            };
            timer.Elapsed += (sender, e) => Out_Event(t);
            timer.Start();
        }
    }
}